#ifndef SINGLETON_MACRO_H
#define SINGLETON_MACRO_H

#include <mutex>
#include <memory>

// 定义一个宏，自动生成单例模式的代码
#define DECLARE_SINGLETON(ClassName) \
public: \
    static ClassName& instance() { \
        static std::once_flag s_flag; \
        static std::unique_ptr<ClassName> s_instance; \
        std::call_once(s_flag, []() { \
            s_instance.reset(new ClassName()); \
        }); \
        return *s_instance.get(); \
    } \
    ClassName(const ClassName&) = delete; \
    ClassName& operator=(const ClassName&) = delete; \
private: \
    ClassName() = default;

#endif // SINGLETON_MACRO_H
